// morfology.cpp : Defines the entry point for the console application.
//

#define TESTMORF
#define GRAYSCALE
#define SHOWPROGRESS

#include <stdio.h>
#include <tchar.h>
#include <iostream>

using namespace std;

#include "../core/morphology.h"

const int num_pattern = 10;
char* spattern[] = 
{ 
	    "0.bmp",
		"1.bmp",
		"2.bmp",
		"3.bmp",
		"4.bmp",
		"5.bmp",
		"6.bmp",
		"7.bmp",
		"8.bmp",
		"9.bmp"
};

const int num_samples = 1;
char* ssample[] = 
{
					//"sample0.bmp",
					"sample2.bmp"
};

const int res_by_pattern = 10;
const double different_low_bound = 0.2;


int _tmain(int argc, _TCHAR* argv[])
{
	CImg sample[num_samples];
	CPattern pattern[num_pattern];
	CFindRes findres[num_pattern];
	for(int i = 0; i < num_samples; i++)
	{
		InitImg(ssample[i], &sample[i]);
	}
	for(int i = 0; i < num_pattern; i++)
	{
	  InitPattern(spattern[i], &pattern[i]);
	  InitFindRes(&findres[i], res_by_pattern);
	}
	for(int i = 0; i < num_samples; i++)
	{
		Find2(&sample[i], pattern, num_pattern, different_low_bound, findres);
		for(int j = 0; j < num_pattern; j++)
		{
			cout << "Pattern " << spattern[j] << " found in " 
				 << ssample[i] << " " << findres[j].numres << " times:" << endl;
			for(int k = 0; k < findres[j].numres; k++)
			{
				cout << "Dist = " << findres[j].res_dist[k] << " X = " << findres[j].res_pos[k].x
					<< " Y = " << (sample[i].height - findres[j].res_pos[k].y) << endl;
			}
			cout << endl;
		}
		cout << endl;
	}
	cout << "Press any key..." << endl;
	char ch; cin >> ch;
	for(int i = 0; i < num_samples; i++)
	{
		DestroyImg(&sample[i]);
	}
	for(int i = 0; i < num_pattern; i++)
	{
		DestroyPattern(&pattern[i]);
		DestroyFindRes(&findres[i]);
	}
	return 0;
}

